package com.cnaaa.xinqiao.service.impl;

import com.cnaaa.xinqiao.dao.BaseDao;
import com.cnaaa.xinqiao.dao.MemberDao;
import com.cnaaa.xinqiao.dto.Tuple2;
import com.cnaaa.xinqiao.entity.Member;
import com.cnaaa.xinqiao.service.MemberService;
import com.cnaaa.xinqiao.util.CollectionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 2018/10/19 Create by 郭文梁
 * MemberServiceImpl
 * 用户服务类实现
 *
 * @author 郭文梁
 * @date 2018/10/19
 */
@Service
@Slf4j
public class MemberServiceImpl extends BaseServiceImpl<Member> implements MemberService {
    private final MemberDao memberDao;

    @Autowired
    public MemberServiceImpl(MemberDao memberDao) {
        this.memberDao = memberDao;
    }

    @Override
    BaseDao<Member> getRepository() {
        return memberDao;
    }

    @Override
    public Map<String, Integer> numberOfPeoplePerDistrict() {
        List<Tuple2<Integer, Integer>> queryResult = memberDao.numberOfPeoplePerDistrict();
        return CollectionUtil.toMap(queryResult, s -> s.getV1() + "区", Tuple2::getV2);
    }
}
